import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		store: {},
		user: uni.getStorageSync("user-info") || {},
		isLogin: !!uni.getStorageSync("user-info"),
		token: uni.getStorageSync("token") || ""
	},
	//获取数据
	getters: {
		//
		user: state => state.user,
		isLogin: state => state.isLogin
	},
	//修改数据
	mutations: {
		SET_USER(state, data) {
			state.user = data.userInfo;
			state.token = data.token;
			state.isLogin = true;
			uni.setStorage({
				key: "user-info",
				data: state.user
			});
			uni.setStorage({
				key: "token",
				data: state.token
			});
		},
		UPDATE_USER(state, data) {
			state.user[data.proper] = data.value;
			uni.setStorage({
				key: "user-info",
				data: state.user
			});
		},
		DEL_USER(state) {
			state.user = {};
			state.token = "";
			state.isLogin = false;
			uni.removeStorageSync("user-info");
			uni.removeStorageSync("token");
		}
	},
	// 异步修改数据
	actions: {

	}
})

export default store